<?php
/*
 * Created on 2009-7-19
 *
 * Author: guobin@yizin.net
 */
global $header;
global $footer;
global $menu;
global $message;
global $users;
global $pageNav;
global $facet;
global $keyword;

global $featureManager;
$header['title'] = '用户列表 - 用户管理';
$header['head'] = '';
$featureManager->apply("com.yizin.platform.admin.header", $header);
$menu['current'] = 'user.user';
$featureManager->apply("com.yizin.platform.admin.menu", $menu);
$featureManager->apply("com.yizin.platform.admin.footer", $footer);
?>
<?= $header['html'] ?>

<div class="ysi-container-C"><div class="ysi-container-CI">
	<form id="delete-form" action="<?=REQUEST_BASE?>admin/user/user/delete/" method="post">
		<input type="hidden" id="serials-input" name="serials" />
	</form>

	<div><?=$message?></div>
	
	<div class="admin-heading"><h2>用户列表</h2></div>
	
	<div>
		<div class="ysi-form">
		<select id="search-facet" style="width:100px" onkeydown="if(event.keyCode==13){document.getElementById('search-button').onclick();}">
			<option value="all">任意属性</option>
			<option value="id"<?=($facet=="id"?' selected="selected"':"")?>>用户名</option>
			<option value="email"<?=($facet=="email"?' selected="selected"':"")?>>电子邮件</option>
			<option value="nickname"<?=($facet=="nickname"?' selected="selected"':"")?>>昵称</option>
			<option value="role"<?=($facet=="role"?' selected="selected"':"")?>>角色</option>
		</select>
		<input class="ysi-form-text" id="search-keyword" type="text" value="<?=$keyword?>" onkeydown="if(event.keyCode==13){document.getElementById('search-button').onclick();}" />
		<input class="ysi-form-submit" id="search-button" type="button" value="搜索用户" onclick="var form=document.getElementById('search-form');var keyword=document.getElementById('search-keyword');var facet=document.getElementById('search-facet');window.location.href='<?=REQUEST_BASE?>admin/user/user/'+(keyword.value==''?'':(facet.value+'/'+keyword.value+'/'));" />
		</div>
	</div>
	<div>
		<div class="ysi-form">
		<input class="ysi-form-submit" type="button" value="创建用户" onclick="window.location.href='<?=REQUEST_BASE?>admin/user/user/new/';" />
		<select style="width:100px" id="action-select">
			<option value="">批量动作</option>
			<option value="grant">设置角色</option>
			<option value="delete">删除</option>
		</select>
		<input class="ysi-form-submit" type="button" value="执行" onclick="var select=document.getElementById('action-select');var action=select.options[select.selectedIndex].value; var serialObjs=document.getElementsByName('serial'); var serials=[];for(var i=0;i<serialObjs.length;i++){if(serialObjs[i].checked)serials.push(serialObjs[i].value);}serials=serials.join(','); if(action=='grant' && serials!=''){window.location.href='<?=REQUEST_BASE?>admin/user/role/grant/?userSerials='+serials+'&from=user';}else if(action=='delete' && serials!=''){if(confirm('确定要删除？')){document.getElementById('serials-input').value=serials; document.getElementById('delete-form').submit(); }}" />
		<?=$pageNav?>
		</div>
	</div>
	<table class="ysi-table">
		<tr>
			<th style="width:15px"><input type="checkbox" value="all" onclick="var objs=document.getElementsByName('serial'); for(var i in objs){objs[i].checked=this.checked;}" /></th>
			<th>用户名</th>
			<th>电子邮件</th>
			<th>昵称</th>
			<th>角色</th>
			<th style="width:10em">控制</th>
		</tr>
		<?php if (!$users) {?>
		<tr><td colspan="6"><div class="empty">(没有记录)</div></td></tr>
		<?php } else {
		foreach($users as $user){?>
		<tr>
			<td class="focused"><input type="checkbox" name="serial" value="<?=$user['serial']?>" /></td>
			<td class="focused"><a class="popup" href="<?=REQUEST_BASE?>admin/user/profile/<?=$user['serial']?>/"><?=$user['id']?></a></td>
			<td><?=$user['email']?></td>
			<td><?=$user['nickname']?></td>
			<td><?=$user['role_name']?></td>
			<td>
				<a href="<?=REQUEST_BASE?>admin/user/user/<?=$user['serial']?>/">编辑</a> 
				<a href="<?=REQUEST_BASE?>admin/user/role/grant/?userSerials=<?=$user['serial']?>&from=user">设置角色</a> 
				<a href="#" onclick="if(confirm('确定要删除？')){document.getElementById('serials-input').value='<?=$user['serial']?>'; document.getElementById('delete-form').submit(); }">删除</a>
			</td>
		</tr>
		<?php }}?>
	</table>
	<div>
		<div class="ysi-form">
		<input class="ysi-form-submit" type="button" value="创建用户" onclick="window.location.href='<?=REQUEST_BASE?>admin/user/user/new/';" />
		<select style="width:100px">
			<option>批量动作</option>
			<option>编辑权限</option>
			<option>删除</option>
		</select>
		<input class="ysi-form-submit" type="button" value="执行" />
		<?=$pageNav?>
		</div>
	</div>
</div></div>

<div class="ysi-container-L">
<?= $menu['html'] ?>
</div>

<?= $footer['html'] ?>
